define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/usertwo/index' + location.search,
                    add_url: 'user/usertwo/add',
                    edit_url: 'user/usertwo/edit',
                    del_url: 'user/usertwo/del',
                    multi_url: 'user/usertwo/multi',
                    // import_url: 'user/usertwo/import',
                    chongzhi_url: 'user/usertwo/chongzhi',
                    videoedit_url: 'user/usertwo/videoedit',
                    table: 'user_two',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'go_money', title: __('Go币'), operate:'BETWEEN'},
                        {field: 'wallet', title: __('钱包'), operate:'BETWEEN'},
                        {field: 'wallet_end_time', title: __('理财时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'video_end_time', title: __('观影卡'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'parent_user_id', title: __('Parent_user_id')},
                        {field: 'goods_parent_user_id', title: __('Goods_parent_user_id')},
                        {field: 'invite_code', title: __('Invite_code'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    title: __('充值'),
                                    text: '充值',
                                    // classname: 'btn btn-xs btn-warning btn-addtabs',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-rmb',
                                    url: 'user/usertwo/chongzhi?id={id}'
                                },
                                {
                                    title: __('观影卡'),
                                    text: '观影卡',
                                    // classname: 'btn btn-xs btn-warning btn-addtabs',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-rmb',
                                    url: 'user/usertwo/videoedit?id={id}'
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        chongzhi: function () {
            Controller.api.bindevent();
        },
        videoedit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
